package com.medicine.interceptor;

import com.medicine.utils.base.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author bo.chen
 *
 */
public class WebInterceptor extends BaseController implements HandlerInterceptor {

	protected Logger logger = LoggerFactory.getLogger(this.getClass());

	/**
	 * 请求controller之前执行
	 */
	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler) throws Exception {
		return true;
	}

	/**
	 * 请求controller之后，渲染ModelAndView之前执行
	 */
	@Override
	public void postHandle(HttpServletRequest req, HttpServletResponse resp, Object handler, ModelAndView modelAndView)
			throws Exception {
	}

	/**
	 * 渲染ModelAndView之后执行
	 */
	@Override
	public void afterCompletion(HttpServletRequest req, HttpServletResponse resp, Object handler, Exception ex)
			throws Exception {
	}
	
	/**
	 * 获取请求的uri
	 * 
	 * @param req
	 * @param resp
	 * @return
	 */
	protected String getUri(HttpServletRequest req, HttpServletResponse resp){
		return req.getServletPath();
	}
	
	/**
	 * 判断当前请求是否需要拦截
	 * 
	 * @param path	请求的uri
	 * @return	true : 需要拦截，false : 不需要拦截
	 */
	public boolean doFilter(String path){
		return true;
	}
}

